

// tinify，key 验证，获取压缩次数
function tinifyValidate(tinify) {
  return new Promise((resolve, reject) => {
    tinify.validate(err => {
      if (err) {
        reject(err);
        throw err;
      }
      const count = tinify.compressionCount;
      resolve(count);
    });
  });
}

// tinify 压缩
function tinifyCompress(tinify, filPath) {
  return new Promise((resolve, reject) => {
    tinify.fromFile(filPath).toBuffer((err, resultData) => {
      if (err) {
        reject(err);
        throw err;
      }
      resolve(resultData);
    });
  });
}

// exports.tinifyValidate = tinifyValidate;
// exports.tinifyCompress = tinifyCompress;
module.exports = {
  tinifyValidate,
  tinifyCompress
}
